package org.jsbd.boss.common;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jsbd.boss.domian.IpRange;
import org.jsbd.boss.domian.TPhoneAreaProvinceInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class IpTableHolder {

  private static final Logger                 logger         = LoggerFactory.getLogger(IpTableHolder.class);

  private static IpTableHolder                theInstance    = new IpTableHolder();
  public List<TPhoneAreaProvinceInfo>         mPhoneAreaList = new ArrayList<TPhoneAreaProvinceInfo>();
  private Map<String, TPhoneAreaProvinceInfo> areaMap        = new HashMap<String, TPhoneAreaProvinceInfo>();
  public List<IpRange>                        ipRangeList    = new ArrayList<IpRange>();

  private IpTableHolder() {
  }

  public static IpTableHolder getInstance() {
    return theInstance;
  }

  public void loadPhoneAreaToMemory(List<TPhoneAreaProvinceInfo> phoneAreaList) {
    mPhoneAreaList.addAll(phoneAreaList);
    if (mPhoneAreaList != null && !mPhoneAreaList.isEmpty()) {
      for (TPhoneAreaProvinceInfo info : mPhoneAreaList) {
        areaMap.put(info.getPhoneNumber(), info);
      }
    }
    logger.info("load all phone area info to memory, size=[{}]", phoneAreaList.size());
  }

  public List<TPhoneAreaProvinceInfo> getmPhoneAreaList() {
    return mPhoneAreaList;
  }

  public Map<String, TPhoneAreaProvinceInfo> getAreaMap() {
    return areaMap;
  }


	public void loadIpToMemory(List<IpRange> ipList) {
		ipRangeList.addAll(ipList);
		logger.info("load all ip info to memory, size=[{}]", ipRangeList.size());
	}

	public List<IpRange> getIpRangeList() {
		return ipRangeList;
	}

	public void setIpRangeList(List<IpRange> ipRangeList) {
		this.ipRangeList = ipRangeList;
	}

}
